package com.demo.lps;

/**
 * Created by china on 2017/6/21.
 */
public abstract class AbstractGun {
    public abstract void shoot();
}

class Handgun extends AbstractGun {

    public void shoot() {
        System.out.println("手枪射击");
    }
}

class Rifle extends AbstractGun {

    public void shoot() {
        System.out.println("步枪射击");
    }
}

class MachineGun extends AbstractGun {

    public void shoot() {
        System.out.println("机枪扫射");
    }
}

class Soldier {
    private AbstractGun gun;

    public AbstractGun getGun() {
        return gun;
    }

    public void setGun(AbstractGun gun) {
        this.gun = gun;
    }

    public void killEnemy() {
        System.out.println("士兵开始杀敌");
        gun.shoot();
    }

}

class Client {
    public static void main(String[] args) {
        Soldier soldier = new Soldier();
        soldier.setGun(new Rifle());
        soldier.killEnemy();
    }
}







